package com.hm.scala.regular

class Person {

  def output() {
    println("person")
  }
}

case class Farmer(age: Int) extends Person {

  override def output() {
    println("Framer age =>" + age)
  }
}

case class Worker(name: String, age: Int) extends Person {

  override def output() {
    println("Worker(" + name + ") age =>" + age)
  }
}

object Person {

  def main(args: Array[String]): Unit = {
    var p: Person = Worker("张三", 18);

    p match {
      case a: Farmer => a.output();
      case b: Worker => b.output();
      case _         => println("没找到对应数据")
    }

    //字符串也支持match
    var str = "fail";
    str match {
      case "ok"                      => println("ok数据")
      case _ if ("fail".equals(str)) => println("fail") //守卫
      case _                         => println("数据没找到")
    }

  }
}